home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / XONE23.ASM < prev    next >
Assembly Source File  |  1987-10-12  |  16KB  |  753 lines

  1.     page    75,132
  2.     title    XONE - Make one ARC file from a member file
  3.  
  4. ; usage:
  5. ;       XONE inputname[.ARC] [filename] [outputname] [/R]
  6. ;
  7. ; remarks:
  8. ;    The 'inputname' is required. It defines the ARC archive
  9. ;    file which contains the member files that you want to extract.
  10. ;    The extension defaults to .ARC.
  11. ;
  12. ;    The 'filename' is optional. If omitted, all files in the
  13. ;    archive are extracted. If supplied, only that file in the
  14. ;    archive that matches the 'filename' is extracted.
  15. ;    Each extracted file is created in the ARC format using the
  16. ;    the original file name.
  17. ;
  18. ;    The 'outputname' is optional. If supplied, it defines the name
  19. ;    to be used for the extracted file. To use this operand, you must
  20. ;    also supply the 'filename' operand to extract a single file.
  21. ;
  22. ; restrictions:
  23. ;    XONE was written by Vernon Buerg and is for use without
  24. ;    restrictions. Please try to distribute this program as-is,
  25. ;    and without modification.
  26.  
  27.     .xlist
  28. print    macro    name            ; display a field
  29.     mov    dx,offset name
  30.     call    prints
  31.     endm
  32.  
  33. printl    macro    text,ctl        ; display a literal
  34.     local    txt,nxt
  35.     mov    dx,offset txt
  36.     call    prints
  37.     jmp    nxt
  38. txt    db    cr,lf,&text
  39.     ifnb    < ctl>
  40.     db    cr,lf,stopper
  41.     else
  42.     db    stopper
  43.     endif
  44. nxt    equ    $
  45.     endm
  46.  
  47.     .sall
  48.     .list
  49.  
  50. header    struc                ; archive header
  51. mbrcode db    0            ;  compression code
  52. mbrname db    13 dup (0)        ;  file name
  53. mbrsize dw    0,0            ;  file size in archive
  54. mbrdate dw    0            ;  creation date
  55. mbrtime dw    0            ;  creation time
  56. mbrcrc    dw    0            ;  cyclic redunancy check
  57. mbrlen    dw    0,0            ;  true file size, bytes
  58. header    ends
  59.  
  60. cseg    segment public para 'CODE'
  61.     assume    cs:cseg,ds:cseg,es:cseg
  62.     org    100h
  63.  
  64. xone    proc    far
  65.     jmp    start            ; do our thing
  66.  
  67. version db    cr,'   ',cr,lf          ; overlay jmp above
  68.     db    '  XONE   Make ARC file from member file(s) ',cr,lf
  69.     db    '  ----   Version 2.3 - by Vern Buerg',cr,lf,stopper
  70. usage    db    cr,lf,'  usage: XONE  archive[.ARC]  [filespec] [output] [/R]'
  71.     db    cr,lf,eof
  72.     db    stopper         ; 2.3, oops
  73.     page
  74. ;
  75. ;    return with error
  76.  
  77. error:    mov    ax,cs            ; insure seg regs
  78.     mov    ds,ax            ;  for proper exit
  79.     mov    sp,cs:stkptr
  80.     mov    errlvl,1        ; set bad return code
  81. ;    mov    dl,7            ; send bel char
  82. ;    mov    ah,2            ;  to standard output
  83. ;    int    21h
  84.  
  85. ;    set DOS error level and exit
  86.  
  87. exit:    mov    sp,cs:stkptr        ; just in case
  88.     mov    al,errlvl        ; return code
  89.     mov    ah,4ch            ; exit function
  90.     int    21h
  91.  
  92.     subttl    '--- constants, equates and work areas'
  93.     page
  94.  
  95. cr    equ    13
  96. lf    equ    10
  97. bel    equ    7
  98. tab    equ    9
  99. eof    equ    26
  100.  
  101. stopper equ    255        ; end of display line indicator
  102. arcmark equ    26        ; special archive marker
  103. xoneer    equ    9        ; highest compression code used      ;2.2
  104.  
  105. stkptr    dw    0        ; stack pointer upon entry
  106. errlvl    db    0        ; dos error level returned
  107. psp    dw    0        ; addr of psp
  108.  
  109. prompt    db    ' already exists, re-use it? (y/N) ',stopper
  110. answer    db    'n',cr,stopper
  111. found    db    0        ; indicates if found a member
  112. reuse    db    0        ; non-zero means overwrite existing file(s)
  113.  
  114. notfnd    db    cr,'  Member file not found - '
  115. member    db    13 dup (0),0    ; selected member name
  116.     db    cr,lf,stopper
  117.  
  118. archdl    dw    0        ; ARC file handle
  119. arcname db    76 dup (stopper)
  120.  
  121. outmsg    db    ' -> '          ; tells you what is being used
  122. outname db    76 dup (0)    ; output file name
  123.  
  124. ;    i/o control variables
  125.  
  126. inbufsz equ    18*1024     ; size of input buffer
  127. inadr    dw    offset inbuf    ; offset to input buffer
  128. inptr    dw    offset inbuf    ; offset to current byte
  129. insize    dw    inbufsz     ; size of input buffer
  130. inlen    dw    0        ; bytes left in buffer
  131. incurh    dw    0        ; current file offset
  132. incurl    dw    0        ;  low word
  133.  
  134. outbufsz equ    18*1024     ; size of output buffer
  135. outlen    dw    outbufsz    ; bytes empty in output buffer
  136. outadr    dw    offset outbuf    ; offset to output buffer
  137. outptr    dw    offset outbuf    ; spot for next output char
  138. outsize dw    outbufsz    ; size of output buffer
  139. outhdl    dw    0        ; output file handle
  140.  
  141. vline    db    cr,lf
  142. vstyle    db    '        '      ; compression method
  143.     db    'ed: '
  144. vname    db    12 dup (0),0
  145.     db    stopper,0
  146.  
  147. styles    db    '     sav'      ; 1 = old, no compression
  148.     db    '     Sav'      ; 2 = new, no compression
  149.     db    '    Pack'      ; 3 = dle for repeat chars
  150.     db    '  Squeez'      ; 4 = huffman encoding
  151.     db    '  crunch'      ; 5 = lz, no crc
  152.     db    '  crunch'      ; 6 = lz with crc
  153.     db    '     SEA'      ; 7 = internal SEA use
  154.     db    '  Crunch'      ; 8 = new lz with crc
  155.     db    '  squash'      ; 9 = pk squashing
  156.  
  157. wtg    dw    0        ; index into where table
  158.  
  159. where    dw    offset copy1    ; offset to routines for each type
  160.     dw    offset copy2
  161.     dw    offset unpack3
  162.     dw    offset unsqueez4
  163.     dw    offset uncrunch5
  164.     dw    offset uncrunch6
  165.     dw    offset uncrunch7
  166.     dw    offset uncrunch8
  167.     dw    offset unsquash9
  168.  
  169.     subttl    '--- mainline processing'
  170.     page
  171. ;
  172. ;    gather command line operands
  173.  
  174. start:
  175.     mov    stkptr,sp        ; save stack ptr
  176.     mov    ax,cs
  177.     mov    ds,ax            ; set local data seg
  178.     mov    cx,es
  179.     mov    psp,cx            ; save psp addr
  180.     mov    es,ax
  181.  
  182.     print    version         ; display program version
  183.  
  184.     mov    si,80h            ; get command line operand
  185.     sub    cx,cx
  186.     or    cl,byte ptr [si]    ; any operand?
  187.     jnz    parm1
  188.  
  189. parm_error:
  190.     print    usage            ; no, gotta have the ARC name
  191.     jmp    error
  192.  
  193. ;    pick off any trailing '/R' parameter
  194.  
  195. parm1:    inc    si            ; point to operand
  196.     mov    bx,si
  197.     add    bx,cx            ; point to end of command line
  198.     cmp    word ptr -2[bx],'R/'    ; is reuse specified?
  199.     je    parm1r
  200.     cmp    word ptr -2[bx],'r/'
  201.     jne    parm2
  202. parm1r: or    reuse,1         ; indicate no checking
  203.     mov    word ptr -2[bx],0d0dh    ; stop command line here
  204.     sub    cx,2            ; remove /R from command line
  205.     jle    parm_error        ; oops, something is missing
  206.  
  207. ;    get first operand - input archive file name
  208.  
  209. parm2:    lodsb                ; strip leading blanks
  210.     cmp    al,' '
  211.     loope    parm2
  212.     mov    di,offset arcname
  213.     stosb
  214.  
  215. parm3:    lodsb                ; copy ARC filename
  216.     cmp    al,cr            ; end of name?
  217.     je    parm4
  218.     cmp    al,' '                  ; delimiter?
  219.     je    parm4
  220.     cmp    al,tab            ; delimiter?
  221.     je    parm4
  222.     cmp    al,','                  ; delimiter?
  223.     je    parm4
  224.     stosb
  225.     cmp    al,'.'                  ; got extension now?
  226.     je    parm5            ; yup, that's nice
  227.     loop    parm3
  228.  
  229. parm4:    mov    ax,'A.'                 ; append default ext
  230.     stosw
  231.     mov    ax,'CR'
  232.     stosw
  233.     jmp    short parm6
  234.  
  235. ;    strip trailing blanks looking for second operand
  236.  
  237. parm5:    lodsb                ; next ext char
  238.     cmp    al,cr            ; end of it?
  239.     je    parm6
  240.     cmp    al,' '                  ; delimiter?
  241.     je    parm6
  242.     cmp    al,tab            ; another delimiter?
  243.     je    parm6
  244.     stosb                ; copy supplied extension
  245.     loop    parm5
  246. parm5a: dec    di            ; back up to end of ext
  247.  
  248. parm6:    mov    al,0            ; append asciiz stopper
  249.     stosb
  250.  
  251. ;    copy optional second (file selection) operand
  252.  
  253.     or    cx,cx            ; another operand?
  254.     jz    parm_done        ; nope, extract all files
  255.     mov    di,offset member
  256. parm7:    lodsb
  257.     cmp    al,cr            ; end of operand?
  258.     je    parm20            ; yes, done
  259.     cmp    al,' '                  ; delimiter for third operand?
  260.     je    parm10
  261.     cmp    al,tab
  262.     je    parm10
  263.     cmp    al,'a'                  ; lower case?
  264.     jb    parm8
  265.     sub    al,32
  266. parm8:    stosb
  267.     loop    parm7
  268. parm9:    mov    ax,0ff00h        ; append asciiz stopper
  269.     stosw
  270.     jmp    short parm_done
  271.  
  272. ;    get third operand, if any, as output file name
  273.  
  274. parm10: sub    cx,1            ; account for delimiter
  275.     jle    parm_done
  276.     mov    di,offset outname    ; third operand is target filename
  277. parm11: lodsb
  278.     cmp    al,' '                  ; strip leading blanks
  279.     loope    parm11
  280.     cmp    al,cr            ; ending c/r?
  281.     je    parm_done        ;  just trailing blanks, then
  282.     jcxz    parm20
  283. parm12: stosb                ; blindly copy the rest
  284.     lodsb
  285.     cmp    al,cr
  286.     loopne    parm12
  287. parm20: mov    ax,0ff00h        ; append stoppers
  288.     stosw
  289.  
  290. parm_done:                ; hope we've got everything
  291.     call    openarc         ; access the archive file
  292.     jnc    xonenext
  293.     ret
  294.  
  295.     page
  296. ;
  297. ;    process next archive header entry
  298.  
  299. xonenext:
  300.     call    gethdr            ; load next header
  301.     jnc    xone2            ; get CF at end of file, etc
  302.     jmp    exit            ; all done
  303.  
  304. xone2:    cmp    archdr.mbrcode,0    ; archive eof?
  305.     jne    xone2a            ; nope, keep on truckin
  306.  
  307.     printl    ' '                     ; blank line
  308.  
  309.     call    closarc         ; close file
  310.     cmp    member,0        ; selecting one file?
  311.     je    xone_ok         ; no, skip next
  312.     cmp    found,0         ; and did we get it?
  313.     jne    xone_ok
  314.     print    notfnd
  315.     printl    ' '
  316. xone_ok:
  317.     jmp    exit            ; depart
  318.  
  319. xone2a:
  320.     cmp    member,0        ; selecting one file?
  321.     je    xonego            ; no, skip next
  322.     mov    si,offset member    ; yes, compare names
  323.     mov    di,offset archdr.mbrname
  324.     mov    cx,13
  325. xonesel:
  326.     lodsb
  327.     cmp